import { _decorator, Component, director, Node, Tween, tween, v3, Vec3 } from 'cc';
import { SettlePanel } from './SettlePanel';
import Banner from '../Banner';
import { AudioManager, Audios } from '../AshFramework/Managers/AudioManager';
const { ccclass, property } = _decorator;

const minX: number = -275;
const maxX: number = 275;

@ccclass('Multiple')
export class Multiple extends Component {
    @property(Node)
    Arrows: Node = null;

    @property({ type: Number })
    Dis: number[] = [];

    private _arrowsPos: Vec3 = Vec3.ZERO;
    private _isClick: boolean = false;

    protected onLoad(): void {
        this._arrowsPos = this.Arrows.getPosition().clone();
    }

    protected start(): void {
        this.move();
    }

    move() {
        tween(this.Arrows)
            .to(2, { position: v3(maxX, this._arrowsPos.y, this._arrowsPos.z) }, { easing: `quadInOut` })
            .to(2, { position: v3(minX, this._arrowsPos.y, this._arrowsPos.z) }, { easing: `quadInOut` })
            .union()
            .repeatForever()
            .start();
    }

    click() {
        if (this._isClick) return;
        AudioManager.PlaySound(Audios.Click);
        Banner.Instance.ShowVideoAd(() => {
            this._isClick = true;
            AudioManager.PlaySound(Audios.BankNote);
            Tween.stopAllByTarget(this.Arrows);
            const curDis: number = Math.abs(this.Arrows.getPosition().clone().x);
            if (curDis <= this.Dis[0]) {
                SettlePanel.Instance.Multiple = 5;
            } else if (curDis <= this.Dis[1]) {
                SettlePanel.Instance.Multiple = 4;
            } else if (curDis <= this.Dis[2]) {
                SettlePanel.Instance.Multiple = 3;
            } else {
                SettlePanel.Instance.Multiple = 2;
            }
            SettlePanel.Instance.getAward();
            this.scheduleOnce(() => { director.loadScene("Menu"); }, 2);
        })
    }

    click2() {
        if (this._isClick) return;
        this._isClick = true;
        AudioManager.PlaySound(Audios.BankNote);
        SettlePanel.Instance.Multiple = 1;
        SettlePanel.Instance.getAward();
        this.scheduleOnce(() => { director.loadScene("Menu"); }, 2);
    }

}


